package com.ruoyi.web.controller.system.sms;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysSms;
import com.ruoyi.system.service.ISysSmsService;

/**
 * 短信Controller
 * 
 * @author ruoyi
 * @date 2022-10-14
 */
@RestController
@RequestMapping("/system/sms")
public class SysSmsController extends BaseController {
	@Autowired
	private ISysSmsService sysSmsService;

	/**
	 * 查询短信列表
	 */
	@PreAuthorize("@ss.hasPermi('system:sms:list')")
	@GetMapping("/list")
	public TableDataInfo list(SysSms sysSms) {
		startPage();
		List<SysSms> list = sysSmsService.selectSysSmsList(sysSms);
		return getDataTable(list);
	}

	/**
	 * 导出短信列表
	 */
	@PreAuthorize("@ss.hasPermi('system:sms:export')")
	@Log(title = "短信", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, SysSms sysSms) {
		List<SysSms> list = sysSmsService.selectSysSmsList(sysSms);
		ExcelUtil<SysSms> util = new ExcelUtil<SysSms>(SysSms.class);
		util.exportExcel(response, list, "短信数据");
	}

	/**
	 * 获取短信详细信息
	 */
	@PreAuthorize("@ss.hasPermi('system:sms:query')")
	@GetMapping(value = "/{ssId}")
	public AjaxResult getInfo(@PathVariable("ssId") Long ssId) {
		return AjaxResult.success(sysSmsService.selectSysSmsBySsId(ssId));
	}

	/**
	 * 新增短信
	 */
	@PreAuthorize("@ss.hasPermi('system:sms:add')")
	@Log(title = "短信", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody SysSms sysSms) {
		return toAjax(sysSmsService.insertSysSms(sysSms));
	}

	/**
	 * 修改短信
	 */
	@PreAuthorize("@ss.hasPermi('system:sms:edit')")
	@Log(title = "短信", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody SysSms sysSms) {
		return toAjax(sysSmsService.updateSysSms(sysSms));
	}

	/**
	 * 删除短信
	 */
	@PreAuthorize("@ss.hasPermi('system:sms:remove')")
	@Log(title = "短信", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ssIds}")
	public AjaxResult remove(@PathVariable Long[] ssIds) {
		return toAjax(sysSmsService.deleteSysSmsBySsIds(ssIds));
	}
}
